package edu.cmu.cs.stage3.alice.authoringtool.editors.responseeditor;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;
import edu.cmu.cs.stage3.alice.authoringtool.datatransfer.CommonMathQuestionsTransferable;
import edu.cmu.cs.stage3.alice.authoringtool.datatransfer.ResponsePrototypeReferenceTransferable;
import edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor;
import edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.MainCompositeElementPanel;
import edu.cmu.cs.stage3.util.StringObjectPair;

public class ResponseEditor extends CompositeElementEditor {

 public final String editorName = "Response Editor";

 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel doIfTruePrototype;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel loopPrototype;
 protected javax.swing.JComponent waitPrototype;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel sequentialLoopPrototype;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel loopIfTruePrototype;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel commentPrototype;
 protected javax.swing.JComponent printPrototype;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel mathPrototype;

 //LOB
 //L Para 'src/edu/cmu/cs/stage3/alice/authoringtool/util/DnDManager.java', via 'void dragDropEnd (java.awt.dnd.DragSourceDropEvent dsde)'
 //L conseguir invocar 'edu.cmu.cs.stage3.alice.authoringtool.editors.responseeditor.CompositeComponentResponsePanel.drop(java.awt.dnd.DropTargetDropEvent dtde)'
 private MainCompositeElementPanel mainCompositeElementPanel = null;
 public  MainCompositeElementPanel getMainCompositeElementPanel () { return mainCompositeElementPanel; }

 public ResponseEditor () {
  super();
  }

 public void setObject (edu.cmu.cs.stage3.alice.core.response.UserDefinedResponse toEdit) {
  clearAllListening();
  this.elementBeingEdited = toEdit;
  // Chama: edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor.updateGui(CompositeElementEditor.java:177)
  // Chamado indiretamente em: edu.cmu.cs.stage3.alice.authoringtool.util.EditorUtilities.editObject(EditorUtilities.java:78)
  updateGui(); // em 'edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor'
  }

 //Rem @Override
 protected java.awt.Color getEditorColor () {
  return AuthoringToolResources.getColor("userDefinedResponseEditor");
  }

 //Rem @Override
 protected MainCompositeElementPanel createElementTree (edu.cmu.cs.stage3.alice.core.Element selected) {
  if (selected instanceof edu.cmu.cs.stage3.alice.core.response.CompositeResponse) {
   MainCompositeResponsePanel toReturn = null;
   if (selected instanceof edu.cmu.cs.stage3.alice.core.response.DoInOrder) {
    // Chamado: edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor.updateGui(CompositeElementEditor.java:177)
    toReturn = new MainSequentialResponsePanel();
    toReturn.set(selected, authoringTool);
    }
   else if (selected instanceof edu.cmu.cs.stage3.alice.core.response.DoTogether) {
    toReturn = new MainParallelResponsePanel();
    toReturn.set(selected, authoringTool);
    }
   return toReturn;
   }
  return null;
  }


 //Rem @Override
 protected void initPrototypes () {
  String doIfTrueString = AuthoringToolResources.getReprForValue(edu.cmu.cs.stage3.alice.core.response.IfElseInOrder.class);
  String loopString = AuthoringToolResources.getReprForValue(edu.cmu.cs.stage3.alice.core.response.LoopNInOrder.class);
  String loopIfTrueString = AuthoringToolResources.getReprForValue(edu.cmu.cs.stage3.alice.core.response.WhileLoopInOrder.class);
  String sequentialLoopString = AuthoringToolResources.getReprForValue(edu.cmu.cs.stage3.alice.core.response.ForEachInOrder.class); // list iterator
  String commentString = AuthoringToolResources.getReprForValue(edu.cmu.cs.stage3.alice.core.response.Comment.class);
  String mathString = AuthoringToolResources.getReprForValue("+ - * /");

  java.awt.Color COUNT_LOOP_COLOR = AuthoringToolResources.getColor("LoopNInOrder");
  java.awt.Color DO_IF_COLOR = AuthoringToolResources.getColor("IfElseInOrder");
  java.awt.Color SEQUENTIAL_LOOP_COLOR = AuthoringToolResources.getColor("ForEachInOrder");
  java.awt.Color COMMENT_COLOR = AuthoringToolResources.getColor("Comment");
  java.awt.Color COMMENT_FOREGROUND = AuthoringToolResources.getColor("commentForeground");
  java.awt.Color DO_WHILE_COLOR = AuthoringToolResources.getColor("WhileLoopInOrder");
  java.awt.Color MATH_COLOR = AuthoringToolResources.getColor("question");

  // System.out.println("ResponseEditor.java: initPrototypes(): -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:");

  doIfTruePrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel();
  doIfTruePrototype.setBackground(DO_IF_COLOR);
  javax.swing.JLabel DITLabel = new javax.swing.JLabel(doIfTrueString);
  doIfTruePrototype.add(DITLabel, java.awt.BorderLayout.CENTER);
  String DITdesired[] = {"condition"};
  doIfTruePrototype.setTransferable(
    new ResponsePrototypeReferenceTransferable(
      new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
        edu.cmu.cs.stage3.alice.core.response.IfElseInOrder.class, null, DITdesired)));
  doIfTruePrototype.addDragSourceComponent(DITLabel);

  String CLdesired[] = {"end"};
  loopPrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel();
  loopPrototype.setBackground(COUNT_LOOP_COLOR);
  javax.swing.JLabel LLabel = new javax.swing.JLabel(loopString);
  loopPrototype.add(LLabel, java.awt.BorderLayout.CENTER);
  loopPrototype.setTransferable(
    new ResponsePrototypeReferenceTransferable(
      new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
        edu.cmu.cs.stage3.alice.core.response.LoopNInOrder.class, null, CLdesired)));
  loopPrototype.addDragSourceComponent(LLabel);

  String LITdesired[] = {"condition"};
  loopIfTruePrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel();
  //loopIfTruePrototype.setBackground(AuthoringToolResources.getColor("WhileLoopInOrder"));
  loopIfTruePrototype.setBackground(DO_WHILE_COLOR);
  javax.swing.JLabel LITLabel = new javax.swing.JLabel(loopIfTrueString);
  loopIfTruePrototype.add(LITLabel, java.awt.BorderLayout.CENTER);
  loopIfTruePrototype.setTransferable(
    new ResponsePrototypeReferenceTransferable(
      new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
        edu.cmu.cs.stage3.alice.core.response.WhileLoopInOrder.class, null, LITdesired)));
  loopIfTruePrototype.addDragSourceComponent(LITLabel);

  // list iterator
  //L String SLdesired[] = {"list"};
  //L sequentialLoopPrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel();
  //L //sequentialLoopPrototype.setBackground(AuthoringToolResources.getColor("ForEachInOrder"));
  //L sequentialLoopPrototype.setBackground(SEQUENTIAL_LOOP_COLOR);
  //L javax.swing.JLabel SLLabel = new javax.swing.JLabel(sequentialLoopString);
  //L sequentialLoopPrototype.add(SLLabel, java.awt.BorderLayout.CENTER);
  //L sequentialLoopPrototype.setTransferable(
  //L   new ResponsePrototypeReferenceTransferable(
  //L     new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
  //L       edu.cmu.cs.stage3.alice.core.response.ForEachInOrder.class, null, SLdesired)));
  //L sequentialLoopPrototype.addDragSourceComponent(SLLabel);

  String Wdesired[] = {"duration"};
  waitPrototype = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getGUI(
    new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(edu.cmu.cs.stage3.alice.core.response.Wait.class, null, Wdesired));

  StringObjectPair Cknown[] = {new StringObjectPair("text", "No comment")};
  commentPrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel(); // --- aqui colocar ouvidor!!!! ---
  commentPrototype.setBackground(COMMENT_COLOR);
  javax.swing.JLabel commentLabel = new javax.swing.JLabel(commentString);
  commentLabel.setForeground(COMMENT_FOREGROUND);
  commentPrototype.add(commentLabel, java.awt.BorderLayout.CENTER);
  commentPrototype.setTransferable(
    new ResponsePrototypeReferenceTransferable(
      new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
        edu.cmu.cs.stage3.alice.core.response.Comment.class, Cknown, null)));
  commentPrototype.addDragSourceComponent(commentLabel);

  printPrototype = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getGUI(
    new edu.cmu.cs.stage3.alice.authoringtool.util.ResponsePrototype(
      edu.cmu.cs.stage3.alice.core.response.Print.class, null, null));

  mathPrototype = new edu.cmu.cs.stage3.alice.authoringtool.util.DnDGroupingPanel();
  mathPrototype.setBackground(MATH_COLOR);
  javax.swing.JLabel mathLabel = new javax.swing.JLabel(mathString);
  int fontSize = 12;
  mathLabel.setFont( new java.awt.Font( "Monospaced", java.awt.Font.BOLD, (int)fontSize) );
  mathPrototype.add(mathLabel, java.awt.BorderLayout.CENTER);
  mathPrototype.setTransferable( new CommonMathQuestionsTransferable() );
  mathPrototype.addDragSourceComponent(mathLabel);

  }

 // Load commands' button at the botton of the working area
 //Rem @Override
 protected void addPrototypes (java.awt.Container prototypeContainer) {

  prototypeContainer.add(doIfTruePrototype);
  prototypeContainer.add(loopPrototype);
  prototypeContainer.add(loopIfTruePrototype);

  // Command button to 'List iterator' - defined by 'edu.cmu.cs.stage3.alice.authoringtool.py.AliceStyle' define 'AuthoringToolResources.putName(...)'
  String str = AuthoringToolResources.getName("edu.cmu.cs.stage3.alice.core.response.ForEachInOrder");
  if (str!=null && str.length()>0)
     prototypeContainer.add(sequentialLoopPrototype);

  prototypeContainer.add(javax.swing.Box.createHorizontalStrut(10));

  // Command button to 'Wait' - defined by 'edu.cmu.cs.stage3.alice.authoringtool.py.AliceStyle' define 'AuthoringToolResources.putName(...)'
  str = AuthoringToolResources.getName("edu.cmu.cs.stage3.alice.core.response.Wait");
  if (str!=null && str.length()>0)
     prototypeContainer.add(waitPrototype);

  prototypeContainer.add(printPrototype);
  prototypeContainer.add(commentPrototype);

  java.awt.Component buttonGlue = javax.swing.Box.createHorizontalGlue();
  prototypeContainer.add(buttonGlue);

  }

 }
